import java.util.HashMap;
import java.util.Map;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * user:likai
 * Date:2023-03-22
 * Time:21:25
 */
class LinkedList {
    class MyLinkedList{
        int val;
        MyLinkedList next;
        public MyLinkedList() {
        }
        public MyLinkedList(int val){
            this.val=val;
        }
    }
    MyLinkedList head;

    public int size(){
        int x=0;
        MyLinkedList cur=head;
        while(cur!=null){
            cur=cur.next;
            x++;
        }
        return x;
    }
    public int get(int index) {
        if(index<0||index>=size()){
            return -1;
        }
        MyLinkedList cur=head;
        while(index>0){
            cur=cur.next;
            index--;
        }
        return cur.val;
    }

    public void addAtHead(int val) {
        MyLinkedList cur=new MyLinkedList(val);
        cur.next=head;
        head=cur;
    }

    public void addAtTail(int val) {
        MyLinkedList cur=new MyLinkedList(val);
        if(head==null){
            head=cur;
        }else{
            MyLinkedList pre=head;
            while(pre.next!=null){
                pre=pre.next;
            }
            pre.next=cur;
        }

    }

    public void addAtIndex(int index, int val) {
        if(index<0||index >size()){
            return;
        }
        if(index==0){
            addAtHead(val);
            return;
        }
        MyLinkedList cur=new MyLinkedList(val);
        MyLinkedList tmp=head;
        for(int i=1;i<index;i++){
            tmp=tmp.next;
        }
        cur.next=tmp.next;
        tmp.next=cur;
    }

    public void deleteAtIndex(int index) {
        if(index<0||index>=size()){
            return;
        }
        if(index==0){
            head=head.next;
            return;
        }
        MyLinkedList cur=head;
        for(int i=0;i<index-1;i++){
            cur=cur.next;
        }
        cur.next=cur.next.next;
    }
}
class ListNode{
    int val;
    ListNode next;
    public ListNode(int val) {
        this.val = val;
    }
}
class Solution {
    public ListNode reverseList(ListNode head) {
        if(head==null){
            return head;
        }
        ListNode node=head.next;
        head.next=null;
        while(node!=null){
            ListNode next=node.next;
            node.next=head;
            head=node;
            node=next;
        }
        return head;
    }
    public ListNode reverseList2(ListNode head) {
        if(head==null){
            return head;
        }
        ListNode next=head.next;
        head.next=null;
        if(next==null){
            return head;
        }
        while(next!=null){
            ListNode tail=next.next;
            next.next=head;
            head=next;
            next=tail;
        }
        return head;
    }
    public ListNode removeElements(ListNode head, int val) {
        while(head!=null&&head.val==val){
            head=head.next;

        }
        if(head==null){
            return head;
        }
        ListNode cur=head;
        ListNode pre=cur;
        while(cur!=null){
            if(cur.val==val){
                pre.next=cur.next;
                cur=cur.next;
            }else{
                pre=cur;
                cur=cur.next;
            }
        }
        return head;
    }
    //两两交换节点
    public ListNode swapPairs(ListNode head) {
        if(head==null||head.next==null){
            return head;
        }
        ListNode slow=head;
        ListNode fast=head.next;
        while(fast!=null){
            int tmp=slow.val;
            slow.val=fast.val;
            fast.val=tmp;
            if(fast.next==null||fast.next.next==null){
                return head;
            }else{
                fast=fast.next.next;
                slow=slow.next.next;

            }
        }
        return head;
    }
    public ListNode removeNthFromEnd(ListNode head, int n) {
        if(n<0){
            return null;
        }
        ListNode cur=new ListNode(-1);
        cur.next=head;
        ListNode fast=cur;
        ListNode slow=cur;
        ListNode pre=slow;
        for(int i=0;i<n;i++){
            if(fast==null){
                return fast;
            }
            fast=fast.next;
        }
        while(fast!=null){
            fast=fast.next;
            pre=slow;
            slow=slow.next;
        }
        pre.next=pre.next.next;
        return cur.next;
    }
    public ListNode detectCycle(ListNode head) {
        if(head==null){
            return null;
        }
        ListNode fast=head;
        ListNode slow=head;
        while(fast.next!=null&&fast.next.next!=null){
            fast=fast.next.next;
            slow=slow.next;
            if(fast==slow){
                fast=head;
                while(fast!=slow){
                    fast=fast.next;
                    slow=slow.next;
                }
                return fast;
            }
        }
        return null;
    }
}
public class Test {
    public static void main(String[] args) {
//        MyLinkedList myLinkedList = new MyLinkedList();
//        myLinkedList.addAtHead(1);
//        myLinkedList.addAtTail(3);
//        myLinkedList.addAtIndex(1, 2);    // 链表变为 1->2->3
//        System.out.println(myLinkedList.get(1));              // 返回 2
//        myLinkedList.deleteAtIndex(1);    // 现在，链表变为 1->3
//        System.out.println(myLinkedList.get(1));              // 返回 3
//        LinkedList myLinkedList=new LinkedList();
//        myLinkedList.addAtHead(1);
//        myLinkedList.deleteAtIndex(0);
//        Integer i=new Integer(1234);
//        int j=1234;
//        System.out.println(i == j);
        HashMap<String,Integer> t=new HashMap<>();
        t.containsKey('s');
        t.put("s",1);
        t.put("s",t.get("s")+1);
        for (Map.Entry<String,Integer> map:t.entrySet()) {
            String s=map.getKey();
            Integer k= map.getValue();
            System.out.println(s+" "+k);
        }
    }
}
